package com.lzy.cloud.ticket.train.facade;

import com.lzy.cloud.ticket.train.constant.LMMApi;
import com.lzy.cloud.ticket.train.constant.LMMContant;
import com.lzy.cloud.ticket.train.request.BaseRequest;
import com.lzy.cloud.ticket.train.request.TimeTableRequest;
import com.lzy.cloud.ticket.train.request.app.TimeTableAppRequest;
import com.lzy.cloud.ticket.train.response.TimeTableResponse;
import com.lzy.cloud.ticket.train.util.BasePushUtil;
import com.lzy.framework.core.utils.DozerUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Component
@Slf4j
public class TimeTableFacade {

    @Resource
    private RestTemplate restTemplate;

    @Autowired
    private BasePushUtil basePushUtil;

    public TimeTableResponse queryTimeTable(TimeTableAppRequest timeTableAppRequest){
        BaseRequest baseRequest = basePushUtil.push(LMMContant.APP_KEY,LMMContant.TIME_TABLE_METHOD,LMMContant.MESSAGE_FORMT,"");
        TimeTableRequest timeTableRequest = DozerUtils.map(baseRequest,TimeTableRequest.class);
        timeTableRequest.setData(timeTableAppRequest);
        TimeTableResponse timeTableResponse = restTemplate.postForObject(LMMApi.TIME_TABLE_URL,timeTableRequest,TimeTableResponse.class);
        return timeTableResponse;
    }
}
